#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
struct point {
    int x, y, z;
    point(int a, int b, int c) : x(a), y(b), z(c) {}
};
bool compare(point& a, point& b) {
    return a.z < b.z;
}
int main() {
    int n;
    cin >> n;
    vector<point> a;
    for(int i = 0; i < n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        a.push_back(point(x, y, z));
    }
    sort(a.begin(), a.end(), compare);
    double ans = 0.0;
    for(int i = 1; i < n; i++) {
        ans = ans + sqrt(pow(a[i].x - a[i - 1].x,2) + pow(a[i].y - a[i - 1].y,2) + pow(a[i].z - a[i - 1].z,2));
    }
    printf("%.3lf", ans);
    return 0;
}